﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Platformer2
{
    /// <summary>
    /// Controls the collision detection and response behavior of a tile.
    /// </summary>
    enum TileCollision
    {
        /// <summary>
        /// A passable tile is one which does not hinder player motion at all.
        /// </summary>
        Passable = 0,

        /// <summary>
        /// An impassable tile is one which does not allow the player to move through
        /// it at all. It is completely solid.
        /// </summary>
        Impassable = 1,

        /// <summary>
        /// A platform tile is one which behaves like a passable tile except when the
        /// player is above it. A player can jump up through a platform as well as move
        /// past it to the left and right, but can not fall down through the top of it.
        /// </summary>
        Platform = 2,

        Break = 3,

    }

    /// <summary>
    /// Stores the appearance and collision behavior of a tile.
    /// </summary>
    struct Tile
    {
        
        public Rectangle localRect;
        public Texture2D Texture;
        public TileCollision Collision;
        public Vector2 Position
        {
            get { return position; }
        }
        public Vector2 position;
#if ZUNE
        public const int Width = 30;
        public const int Height = 20;
#else
        public const int Width = 64;
        public const int Height = 48;    
        
#endif
        public static readonly Vector2 Size = new Vector2(Width, Height);
        
        public bool MovePossible;

        /// <summary>
        /// Constructs a new tile.
        /// </summary>
        public Tile(Texture2D texture, TileCollision collision, bool movePossible, Vector2 pos)
        {
            Texture = texture;
            Collision = collision;
            MovePossible = movePossible;
            this.position = pos;
            int width = Width;
            int left = (int)position.X;
            int height = Height;
            int top = (int)position.Y;
            localRect = new Rectangle(left, top, width, height);
        }
        public void SetPosition(Vector2 pos)
        {
            position = pos;
            int left = (int)Math.Round(position.X - Width) + Width/2;
            int top = (int)Math.Round(position.Y - Height) + Height/2;  
            int width = Width;
            int height = Height;
            localRect = new Rectangle(left, top, width, height);
        }
        public void SetCollision(TileCollision collision)
        {
            Collision = collision;
        }
    }
}
